home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Embed / Sources / Proxy.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  11.7 KB  |  425 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Proxy.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. // ----- Embed Part Includes -----
  15.  
  16. #ifndef PROXY_H
  17. #include "Proxy.h"
  18. #endif
  19.  
  20. #ifndef PART_H
  21. #include "Part.h"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef DEFINES_K
  29. #include "Defines.k"
  30. #endif
  31.  
  32. // ----- ODF Includes -----
  33.  
  34. #ifndef FWFRMING_H
  35. #include "FWFrming.h"
  36. #endif
  37.  
  38. #ifndef FWUTIL_H
  39. #include "FWUtil.h"
  40. #endif
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. #ifndef FWFCTCLP_H
  47. #include "FWFctClp.h"
  48. #endif
  49.  
  50. #ifndef FWODGEOM_H
  51. #include "FWODGeom.h"
  52. #endif
  53.  
  54. #ifndef FWITERS_H
  55. #include "FWIters.h"
  56. #endif
  57.  
  58. #ifndef FWPXYITE_H
  59. #include "FWPxyIte.h"
  60. #endif
  61.  
  62. #ifndef FWMENUS_K
  63. #include "FWMenus.k"
  64. #endif
  65.  
  66. // ----- OpenDoc Includes -----
  67.  
  68. #ifndef SOM_ODShape_xh
  69. #include <Shape.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODTransform_xh
  73. #include <Trnsform.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODSession_xh
  77. #include <ODSessn.xh>
  78. #endif
  79.  
  80. //========================================================================================
  81. // RunTime Info
  82. //========================================================================================
  83.  
  84. #ifdef FW_BUILD_MAC
  85. #pragma segment odfembed
  86. #endif
  87.  
  88. //========================================================================================
  89. //    class CEmbedProxy
  90. //========================================================================================
  91.  
  92. //----------------------------------------------------------------------------------------
  93. //    CEmbedProxy constructors
  94. //----------------------------------------------------------------------------------------
  95.  
  96. CEmbedProxy::CEmbedProxy(Environment* ev, CEmbedPart* part) :
  97.     FW_MProxy(ev, part),
  98.     fPart(part)
  99. {
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    CEmbedProxy::~CEmbedProxy
  104. //----------------------------------------------------------------------------------------
  105.  
  106. CEmbedProxy::~CEmbedProxy()
  107. {
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    CEmbedProxy::AdjustBorderShape
  112. //----------------------------------------------------------------------------------------
  113.  
  114. void CEmbedProxy::AdjustBorderShape(Environment* ev, 
  115.                                     FW_CEmbeddingFrame* embeddingFrame, 
  116.                                     ODFacet* embeddedFacet, 
  117.                                     ODShape* shape)
  118. {
  119. FW_UNUSED(embeddingFrame);
  120. FW_UNUSED(embeddedFacet);
  121.  
  122.     if ((shape == NULL) || (fPart->GetFacetNumberCommandID() == cOneFacet) || (fPart->GetRotation() == 0))
  123.         return;
  124.     else
  125.         shape->Reset(ev);
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    CEmbedProxy::UsedShapeChanged
  130. //----------------------------------------------------------------------------------------
  131. //    Used shape of an embedded frame changed. Just invalidate and recalculate its clip
  132.  
  133. void CEmbedProxy::UsedShapeChanged(Environment* ev,
  134.                                    FW_CEmbeddingFrame* embeddingFrame,
  135.                                    ODFrame* odEmbeddedFrame)
  136. {
  137. FW_UNUSED(odEmbeddedFrame);
  138.  
  139.     // ----- Recalculate the clip -----
  140.     if (fPart->GetFacetNumberCommandID() == cOneFacet)
  141.     {
  142.         // ----- Use the standard facet clipper 
  143.         FW_CFacetClipper clipper;
  144.         clipper.Clip(ev, embeddingFrame);
  145.     }
  146.     else
  147.     {
  148.         //     I cannot use the standard facet clipper because it only works for one facet
  149.         //    Because I know in which order the facets were created I can just iterates 
  150.         FW_CRect clipRects[4];
  151.         EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
  152.         
  153.         short rotation = fPart->GetRotation();
  154.         
  155.         FW_CFrameFacetIterator ite(ev, embeddingFrame);
  156.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  157.         {
  158.             short facetID = 0;
  159.             FW_CFacetIterator ite2(ev, facet);
  160.             for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
  161.             {
  162.                 FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRects[facetID]);
  163.     
  164.                 FW_CAcquiredODShape aqClipShape = FW_NewODShape(ev, clipRects[facetID]);
  165.                 
  166.                 // Update the facet clip shape
  167.                 embeddedFacet->ChangeGeometry(ev, aqClipShape, externalTransform, NULL);
  168.                 facetID++;
  169.             }
  170.         }
  171.     }
  172.  
  173.     embeddingFrame->Invalidate(ev);
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    CEmbedProxy::RotateFacets
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void CEmbedProxy::RotateFacets(Environment* ev, short rotation)
  181. {
  182.     // Loop on all proxy frames
  183.     FW_CProxyProxyFrameIterator ite(this);
  184.     for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  185.     {
  186.         FW_CEmbeddingFrame* embeddingFrame = proxyFrame->GetContainingFrame(ev);
  187.         if (embeddingFrame == NULL)
  188.             continue;
  189.         
  190.         FW_CRect clipRects[4];
  191.         EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
  192.  
  193.         // Loop on all facets of the embedding frame
  194.         FW_CFrameFacetIterator ite(ev, embeddingFrame);
  195.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  196.         {
  197.             // Loop on the 4 embedded facets of each embedding facet
  198.             FW_CFacetIterator ite2(ev, facet);
  199.             short facetID = 0;
  200.             for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
  201.             {
  202.                 FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRects[facetID]);
  203.                 FW_CAcquiredODShape aqClipShape = FW_NewODShape(ev, clipRects[facetID]);
  204.                 
  205.                 // Change the facet's external transform
  206.                 // [LSD] normally I should not have to set the clip shape here since it 
  207.                 //        doesn't change.  But if I don't do it the facets are not always 
  208.                 //      drawn... OpenDoc bug in ChangeGeometry?
  209.                 embeddedFacet->ChangeGeometry(ev, aqClipShape, externalTransform, NULL);
  210.                 facetID++;
  211.             }
  212.         }
  213.         embeddingFrame->Invalidate(ev);
  214.     }    
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. //    CEmbedProxy::FrameShapeRequested
  219. //----------------------------------------------------------------------------------------
  220. //    We always want the embedded frame to have our frame shape
  221.  
  222. ODShape* CEmbedProxy::FrameShapeRequested(Environment* ev, 
  223.                                         FW_CEmbeddingFrame* embeddingFrame, 
  224.                                         ODFrame* odEmbeddedFrame, 
  225.                                         ODShape* requestedFrameShape)
  226. {
  227. FW_UNUSED(requestedFrameShape);
  228. FW_UNUSED(odEmbeddedFrame);
  229.  
  230.     return ((CEmbedFrame*)embeddingFrame)->CreateFrameShape(ev);     // No FW_CAcquiredODShape because we are returning it
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    CEmbedProxy::GetRotationDelta
  235. //----------------------------------------------------------------------------------------
  236.  
  237. static FW_CPoint GetRotationDelta(short rotation, short facetID, const FW_CRect& clipRect)
  238. {
  239.     FW_Fixed x = clipRect.Width() + kBorder;
  240.     FW_Fixed y = clipRect.Height() + kBorder;
  241.     
  242.     FW_CPoint delta(FW_kZeroPoint);
  243.     
  244.     short position = (rotation + facetID) % 4;
  245.     switch (position)
  246.     {
  247.         case 0:
  248.             switch (facetID)
  249.             {
  250.                 case 1:
  251.                     delta.x -= x;
  252.                     break;
  253.                 case 3:
  254.                     delta.y -= y;
  255.                     break;
  256.                 case 2:
  257.                     delta.x -= x;
  258.                     delta.y -= y;
  259.                     break;                    
  260.             }
  261.             break; 
  262.         case 1:
  263.             switch (facetID)
  264.             {
  265.                 case 0:
  266.                     delta.x += x;
  267.                     break;
  268.                 case 3:
  269.                     delta.x += x;
  270.                     delta.y -= y;
  271.                     break;
  272.                 case 2:
  273.                     delta.y -= y;
  274.                     break;                    
  275.             }
  276.             break; 
  277.         case 3:
  278.             switch (facetID)
  279.             {
  280.                 case 0:
  281.                     delta.y += y;
  282.                     break;
  283.                 case 1:
  284.                     delta.x -= x;
  285.                     delta.y += y;
  286.                     break;
  287.                 case 2:
  288.                     delta.x -= x;
  289.                     break;                    
  290.             }
  291.             break; 
  292.         case 2:
  293.             switch (facetID)
  294.             {
  295.                 case 0:
  296.                     delta.x += x;
  297.                     delta.y += y;
  298.                     break;
  299.                 case 1:
  300.                     delta.y += y;
  301.                     break;
  302.                 case 3:
  303.                     delta.x += x;
  304.                     break;                    
  305.             }
  306.             break; 
  307.     }
  308.     
  309.     return delta;
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    CEmbedProxy::GetExternalTransform
  314. //----------------------------------------------------------------------------------------
  315.  
  316. ODTransform* CEmbedProxy::GetExternalTransform(Environment* ev, short rotation, short facetID, const FW_CRect& clipRect)
  317. {
  318.     FW_CPoint delta = GetRotationDelta(rotation, facetID, clipRect);
  319.     
  320.     FW_CPoint origin(delta.x + kBorder, delta.y + kBorder);
  321.         
  322.     return ::FW_NewODTransform(ev, origin);
  323. }
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    CEmbedFrame::CreateOneFacet
  327. //----------------------------------------------------------------------------------------
  328.  
  329. ODFacet* CEmbedProxy::CreateOneFacet(Environment* ev, 
  330.                                     ODFacet* embeddingFacet, 
  331.                                     ODFrame* embeddedFrame, 
  332.                                     ODFacet* sibling,
  333.                                     short rotation,
  334.                                     short facetID,
  335.                                     const FW_CRect& clipRect)
  336. {
  337.     FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRect);
  338.     FW_CAcquiredODShape clipShape = ::FW_NewODShape(ev, clipRect);
  339.     
  340.     return CreateFacet(ev,
  341.                     embeddingFacet,
  342.                     embeddedFrame,
  343.                     clipShape,
  344.                     externalTransform,
  345.                     NULL,                    // Canvas
  346.                     NULL,                    // biasCanvas
  347.                     sibling,                // siblingFacet
  348.                     kODFrameInFront);
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    CEmbedProxy::EmbeddedFacetBounds
  353. //----------------------------------------------------------------------------------------
  354.  
  355. void CEmbedProxy::EmbeddedFacetBounds(Environment* ev, FW_CEmbeddingFrame* frame, FW_CRect* clipRects)
  356. {
  357.     FW_CRect bounds = frame->GetBounds(ev);
  358.     bounds.Place(FW_kFixed0, FW_kFixed0);
  359.     bounds.Inset(kBorder);
  360.  
  361.     FW_CRect embeddedBounds = bounds;
  362.     embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
  363.  
  364.     FW_CPoint embeddedMiddle(FW_Half(embeddedBounds.left + embeddedBounds.right), FW_Half(embeddedBounds.top + embeddedBounds.bottom));
  365.     
  366.     FW_CPoint middle(FW_Half(bounds.left + bounds.right), FW_Half(bounds.top + bounds.bottom));
  367.  
  368.     clipRects[0].Set(FW_kFixed0, FW_kFixed0, embeddedMiddle.x - kHalfBorder, embeddedMiddle.y - kHalfBorder);
  369.     clipRects[1].Set(embeddedMiddle.x + kHalfBorder, FW_kFixed0, embeddedBounds.right, embeddedMiddle.y - kHalfBorder);
  370.     clipRects[2].Set(embeddedMiddle.x + kHalfBorder, embeddedMiddle.y + kHalfBorder, embeddedBounds.right, embeddedBounds.bottom);
  371.     clipRects[3].Set(FW_kFixed0, embeddedMiddle.y + kHalfBorder, embeddedMiddle.x - kHalfBorder, embeddedBounds.bottom);
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. //    CEmbedProxy::CreateFacets
  376. //----------------------------------------------------------------------------------------
  377.  
  378. short CEmbedProxy::CreateFacets(Environment* ev,
  379.                                 FW_CEmbeddingFrame* embeddingFrame,
  380.                                 ODFacet* embeddingFacet,
  381.                                 ODFrame* embeddedFrame,
  382.                                 ODShape* proposedClipShape)
  383. {
  384. FW_UNUSED(proposedClipShape);
  385.     FW_CRect bounds = embeddingFrame->GetBounds(ev);
  386.     bounds.Place(FW_kFixed0, FW_kFixed0);
  387.     bounds.Inset(kBorder);
  388.  
  389.     FW_CRect embeddedBounds = bounds;
  390.     embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
  391.  
  392.     short nbFacet;
  393.     if (fPart->GetFacetNumberCommandID() == cOneFacet)
  394.     {
  395.         CreateOneFacet(ev, embeddingFacet, embeddedFrame, NULL, 0, 0, embeddedBounds);
  396.         nbFacet = 1;
  397.     }
  398.     else
  399.     {
  400.         FW_CRect clipRects[4];
  401.         EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
  402.         short rotation = fPart->GetRotation();
  403.         
  404.         ODFacet* siblingFacet = NULL;
  405.         for (short facetID = 0; facetID < 4; facetID++)
  406.         {
  407.             ODFacet* newFacet = CreateOneFacet(ev, 
  408.                                                 embeddingFacet, 
  409.                                                 embeddedFrame, 
  410.                                                 siblingFacet,
  411.                                                 rotation,
  412.                                                 facetID,
  413.                                                 clipRects[facetID]);
  414.             if (siblingFacet == NULL)
  415.                 siblingFacet = newFacet;
  416.         }
  417.         
  418.         nbFacet = 4;
  419.     }
  420.     
  421.     return nbFacet;
  422. }
  423.  
  424.  
  425.